package com.ta.gulimall.member.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ta.gulimall.member.view.vo.AddressFareVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ta.gulimall.member.view.entity.MemberReceiveAddressEntity;
import com.ta.gulimall.member.service.MemberReceiveAddressService;
import com.ta.gulimall.common.utils.system.PageUtils;
import com.ta.gulimall.common.utils.system.R;



/**
 * 会员收货地址
 *
 * @author tuao
 * @email tuaoo@gmail.com
 * @date 2022-10-29 11:21:52
 */
@RestController
@RequestMapping("member/memberreceiveaddress")
public class MemberReceiveAddressController {
    @Autowired
    private MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 查询会员收货地址集合
     * @param userId
     * @return
     */
    @GetMapping("/deliveryAddress")
    public R deliveryAddressByUserId(Long userId){
        List<MemberReceiveAddressEntity> list = memberReceiveAddressService.deliveryAddress(userId);
        return R.ok(list);
    }

    /**
     * 根据地址Id查询地址信息
     * @param addrId
     * @return
     */
    @GetMapping("/deliveryAddressById")
    public R deliveryAddressById(Long addrId){
        AddressFareVo entity = memberReceiveAddressService.deliveryAddressById(addrId);
        return R.ok(entity);
    }






    //=================以下是系统代码===================
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberReceiveAddressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberReceiveAddressEntity memberReceiveAddress = memberReceiveAddressService.getById(id);

        return R.ok().put("memberReceiveAddress", memberReceiveAddress);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
		memberReceiveAddressService.save(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
		memberReceiveAddressService.updateById(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberReceiveAddressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
